Don't let convert_av_frame_to_frame_output() take ownership of the AVFrame - #1595
Closed
NicolasHug wants to merge 2 commits into
Closed
Don't let convert_av_frame_to_frame_output() take ownership of the AVFrame#1595NicolasHug wants to merge 2 commits into
NicolasHug wants to merge 2 commits into
Conversation
convert_av_frame_to_frame_output() took a non-const UniqueAVFrame&, which let implementations steal the caller's frame. Both CUDA interfaces did: BetaCudaDeviceInterface moved out of it, and CudaDeviceInterface reassigned it with the result of maybe_convert_av_frame_to_nv12_or_rgb24(). That was invisible under SingleStreamDecoder, whose frame is a loop local that dies right after conversion. It is not invisible under the building-block ops, where the frame is owned by a handle that outlives the call: the frame ends up freed twice, corrupting the heap. Take the frame by const reference all the way down the conversion path, so a callee physically cannot move from it or reset it. Where an implementation needs a different frame, it now owns that one separately and binds a const reference to whichever of the two applies -- the idiom convert_audio_av_frame_to_frame_output() already used. maybe_convert_av_frame_to_nv12_or_rgb24() returns a null frame to mean "no conversion needed" instead of handing back the input.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/meta-pytorch/torchcodec/1595
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit df0e0d2 with merge base 3f7692b ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Contributor
Author
|
Superseded by #1598 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
convert_av_frame_to_frame_output()took a non-constUniqueAVFrame&, which let implementations steal the caller's frame (by e.g. callingstd::move()on it as done in theBetaCudaDeviceInterface)This proved to cause subtle ownership issues as I started working on CUDA support for the "Blocks" API - the AVFrame that got
std::moved()would be double-freed.The parameter is now
const, programatically enforcing that ownership remains to the caller.Stack created with GitHub Stacks CLI • Give Feedback 💬